home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Reverting of big array ?
- Date: Tue, 26 Mar 1996 15:16:31 -0800
- Organization: systems hk
- Message-ID: <31587ACF.59D9@teleport.com>
- References: <Pine.SOL.3.91.960326132111.6385A-100000@evolution>
- NNTP-Posting-Host: ip-pdx02-38.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (WinNT; I)
-
- Thomas wrote:
- > I need to revert an array (of chars).
- > I used the folowing code:( l=length of array)
- >
- > char *rev=new char[l+1];
- > for(i=l-1,j=0;i>=0;i--,j++) rev[j]=seq[i];
- > rev[j]='\0';
- >
- > this code works, but is terribly slow, when using an string with
- > size ~ 6000.
- > doing the same with the unix command 'rev' takes 1/2 second.
- > Any ideas ???Thomas,
- It might not be much faster, but I usually use the following:
-
- for( i=0; i<numChars/2; i++ )
- strChars[i] = strChars[numChars-i-1];
-
- Also, your compiler might support a 'string-reverse' function.
- Yours, Geoff Houck
-